package com.project.controller;

import com.project.AOP.HasRole;
import com.project.common.R;
import com.project.entity.GlobalTime;
import com.project.service.GlobalTimeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;

/**
 * ClassName: GlobalTimeController
 * Package: com.project.controller
 * Description:
 *
 * @Author 看到风
 * @Create 2023/11/6 18:18
 * @Version 1.0
 */
@RestController
@RequestMapping("/global_time")
public class GlobalTimeController {
    @Autowired
    private GlobalTimeService globalTimeService;

    @PostMapping("/{code}/{projectId}")
    @Transactional
    @HasRole(2)
    //1.设置全局时间
    public R<String> saveTime(@PathVariable int code,@PathVariable Long projectId, @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate beginDate, @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endDate ){
        globalTimeService.saveGlobalTime( code,beginDate,endDate,projectId);
        return  R.success("设置成功");
    }

    //修改全局时间信息回写
    @GetMapping("/getGlobalTime/{code}/{projectId}")
    public R<GlobalTime> getTime(@PathVariable int code,@PathVariable Long projectId){
        GlobalTime infoTime = globalTimeService.getInfoTime(code,projectId);
        return R.success(infoTime);
    }

    //修改时间
    @PutMapping("/update_time")
    @Transactional
    public R<String> updateGlobalTime(@RequestBody GlobalTime globalTime ){
        globalTimeService.updateTime(globalTime);
        return R.success("修改成功");
    }
}
